/**
A USB interface to the Microchip(tm) PICkit(tm) 1 FLASH Starter Kit
device programmer and breadboard.

Orion Sky Lawlor, olawlor@acm.org, 2003/8/3
*/
#ifndef __OSL_USB_PICKIT_H
#define __OSL_USB_PICKIT_H

#include "pic14.h"

typedef struct usb_dev_handle usb_pickit;

/** Generic abort routine */
void bad(const char *why);

/** Open the pickit as a usb device.  Aborts on errors. */
usb_pickit *usb_pickit_open(void);

/** Turn the device on */
void usb_pickit_on(usb_pickit *d);

/** Turn the device off */
void usb_pickit_off(usb_pickit *d);

/** Fill out this program with the current contents of the device. 
 */
void usb_pickit_read_program(usb_pickit *d,pic14_program *p);

/** Fill out this configuration with the contents of the device. 
 */
void usb_pickit_read_config(usb_pickit *d,pic14_config *c);

/** Fill out this state with the contents of the device. 
 */
void usb_pickit_read(usb_pickit *d,pic14_state *s);

/** Write this state.  If keepOld (RECOMMENDED), will 
   preserve old osccal and BG bits. */
void usb_pickit_write(usb_pickit *d,pic14_state *s,int keepOld);


/** Do a hard chip reset. You *must* preserve config first. 
    This clears both program and config, you must then
    call write_program and merge_config (or write_config).
*/
void usb_pickit_reset(usb_pickit *d);

/** Send this program to the device (requires reset first).
 */
void usb_pickit_write_program(usb_pickit *d,pic14_program *p);

/** Send off this configuration (requires reset first).
    Copies osccal, ID, and BG bits from oldconfig, everything 
    else from newconfig. (these are the preserved bits)
 */
void usb_pickit_merge_config(usb_pickit *d,
	pic14_config *oldconfig, pic14_config *newconfig);

/** Send off this config.  WARNING: do not reset osccal and BG bits!  */
void usb_pickit_write_config(usb_pickit *d,pic14_config *c);

/** Print the whole configuration set (osccal, id, and config word). */
void usb_pickit_print_config(usb_pickit *d);

#endif
